/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package generadorva;

import ec.util.MersenneTwisterFast;
import java.io.PrintWriter;

/**
 *
 * @author USUARIO
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        MersenneTwisterFast prng = new MersenneTwisterFast(75846125);
        Poisson poisson1 = new Poisson(5.0);
        Binomial binomial = new Binomial(20, 0.25);
        Uniforme uniforme = new Uniforme(10.5,20.5);
        Exponencial exponencial = new Exponencial(10);
        double suma = 0d;
        double suma2 = 0d;
        double sumap = 0d;
        double suma2p = 0d;
        double sumau = 0d;
        double suma2u = 0d;
        double sumae = 0d;
        double suma2e = 0d;
        int n = 1000000;
        try {
            //PrintWriter printer = new PrintWriter("salida.txt");
            for (int i = 0; i < n; i++) {
                double u = prng.nextDouble();
                int x = poisson1.generate(u);
                int y = binomial.generate(u);
                double z = uniforme.generate(u);
                double w = exponencial.generate(u)*60; // el 60 es por 60 minutos
                suma += x;
                suma2 += x*x;
                sumap += y;
                suma2p += y*y;
                sumau += z;
                suma2u += z*z;
                //printer.println(z);
                sumae += w;
                suma2e += w*w;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        

        double media = suma/n;
        double varianza = (suma2 - n*media*media)/(n-1);
        System.out.println("Distribucion Poisson:");
        System.out.println("k= " + poisson1.getK());
        System.out.println("media= "+ media);
        System.out.println("varianza = " + varianza);

        double mediap = sumap/n;
        double varianzap = (suma2p - n*mediap*mediap)/(n-1);
        System.out.println("\n\nDistribucion Binomial:");
        System.out.println("probabiilidad de exito: " +binomial.getP());
        System.out.println("numero de ensayos: " + binomial.getN());
        System.out.println("media= "+ mediap);
        System.out.println("varianza = " + varianzap);

        double mediau = sumau/n;
        double varianzau = (suma2u - n*mediau*mediau)/(n-1);
        System.out.println("\n\nDistribucion Uniforme:");
        System.out.println("a: " + uniforme.getA());
        System.out.println("b: " + uniforme.getB());
        System.out.println("probabilidad: " + uniforme.getP());
        System.out.println("media= "+ mediau);
        System.out.println("varianza = " + varianzau);

        double mediae = sumae/n;
        double varianzae = (suma2e - n*mediae*mediae)/(n-1);
        System.out.println("\n\nDistribucion Exponencial:");
        System.out.println("Lambda: " + exponencial.getLambda());
        System.out.println("media= "+ mediae);
        System.out.println("varianza = " + varianzae);
    }

}
